// pages/index/index.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    nbFrontColor: "#000000",
    nbbackgrundColor: "ffffff",
    active: 0,
    getId: "",
    pictureListId: "",
    videoListId: "",
    swiperList: [],
    show: false,
    activeKey: 0,
    title: [],
    titleList1: [],
    titleList2: [],
    videoList: [],
    menuList: ["公司团队", "摄影师专题", "相册", "视频", "预约"],
  },

  goPicture(event) {
    const getId = event.currentTarget.dataset.item.id;
    wx.redirectTo({
      url: `../pictureDetails/pictureDetails?id=${getId}&name=index`,
    });
  },
  /**{}
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      nbTitle: "新标题",
      nbLoading: true,
      nbFrontColor: "#ffffff",
      nbBackgroundColor: "#000000",
    });
    wx.request({
      url:
        "https://yingshi.saas.youyougoo.com/app-user-api/yingshi/album-type/getList",
      method: "GET",
      header: {
        "tenant-id": "155",
        "Authorization": "Bearer test131",
      },
      success: (res) => {
        const arr1 = [];
        const arr2 = [];
        res.data.data.forEach((item) => {
          if (item.type === 0 && item.enable === true) {
            arr1.push(item);
          } else if (item.type === 1 && item.enable === true) {
            arr2.push(item);
          }
        });
        if(arr1.length > 0 && arr2.length == 0){
          this.setData({
            titleList2: arr2,
            title: arr1, // 更新 title 数组
            pictureListId: arr1[0].id,
          });
        }else if(arr2.length > 0 && arr1.length == 0){
          this.setData({
            titleList2: arr2,
            title: arr1, // 更新 title 数组
            videoListId: arr2[0].id,
          });
        }else if(arr2.length > 0 && arr1.length > 0){
          this.setData({
            titleList2: arr2,
            title: arr1, // 更新 title 数组
            pictureListId: arr1[0].id,
            videoListId: arr2[0].id,
          });
        }
        // 使用 this.setData() 更新页面数据
        this.getactionList()
      },
      fail: (err) => {
        console.error(err);
      },
    });
    // const currentIndex = Number(event.detail.index);
    // const currentId = this.data.title[1].id;
    // console.log(currentId);
    // 图片

    // 轮播图查询
    wx.request({
      url:
        "https://yingshi.saas.youyougoo.com/app-user-api/yingshi/album/getbanneralbums",
      method: "GET",
      header: {
        "tenant-id": "155",
        "Authorization": "Bearer test131",
      },
      success: (res) => {
        const arr1 = [];
        res.data.data.forEach((item) => {
            arr1.push(item);
        });
        // 使用 this.setData() 更新页面数据
        this.setData({
          // 假设res.data是你要更新的数据
          swiperList: arr1,
        });
      },
      fail: (err) => {
        console.error(err);
      },
    });
  },

  getactionList(){
    wx.request({
      url:
        "https://yingshi.saas.youyougoo.com/app-user-api/yingshi/album/simplepage",
      method: "POST",
      header: {
        "tenant-id": "155",
        "Authorization": "Bearer test131",
      },
      data: {
        pageNo: 1,
        pageSize: 10,
        albumTypeId: Number(this.data.pictureListId),
      },
      success: (res) => {
        // 使用 this.setData() 更新页面数据
        this.setData({
          // 假设res.data是你要更新的数据
          titleList1: res.data.data.list,
        });
      },
      fail: (err) => {
        console.error(err);
      },
    });
    // 视频
    wx.request({
      url:
        "https://yingshi.saas.youyougoo.com/app-user-api/yingshi/album/simplepage",
      method: "POST",
      header: {
        "tenant-id": "155",
        "Authorization": "Bearer test131",
      },
      data: {
        pageNo: 1,
        pageSize: 10,
        albumTypeId: Number(this.data.videoListId),
      },
      success: (res) => {
        // 使用 this.setData() 更新页面数据
        this.setData({
          // 假设res.data是你要更新的数据
          videoList: res.data.data.list,
        });
      },
      fail: (err) => {
        console.error(err);
      },
    });
  },
  
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},
  onChange(event) {
    const currentId = event.detail.name;
    wx.request({
      url:
        "https://yingshi.saas.youyougoo.com/app-user-api/yingshi/album/simplepage",
      method: "POST",
      header: {
        "tenant-id": "155",
        "Authorization": "Bearer test131",
      },
      data: {
        pageNo: 1,
        pageSize: 10,
        albumTypeId: currentId,
      },
      success: (res) => {
        // 使用 this.setData() 更新页面数据
        this.setData({
          // 假设res.data是你要更新的数据
          titleList1: res.data.data.list,
        });
      },
      fail: (err) => {
        console.error(err);
      },
    });
  },
  onChange1(event) {
    console.log(event);
    const currentId = event.detail.name;
    wx.request({
      url:
        "https://yingshi.saas.youyougoo.com/app-user-api/yingshi/album/simplepage",
      method: "POST",
      header: {
        "tenant-id": "155",
        "Authorization": "Bearer test131",
      },
      data: {
        pageNo: 1,
        pageSize: 10,
        albumTypeId: currentId,
      },
      success: (res) => {
        // 使用 this.setData() 更新页面数据
        this.setData({
          // 假设res.data是你要更新的数据
          videoList: res.data.data.list,
        });
      },
      fail: (err) => {
        console.error(err);
      },
    });
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
